package com.pesoexpress.bypass.endpoint;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.pesoexpress.operations.schema.EnvioRequest;
import com.pesoexpress.operations.schema.EnvioResponse;
import com.pesoexpress.operations.schema.PesoExpressResp;
import com.pesoexpress.operations.schema.RetiroRequest;
import com.pesoexpress.operations.schema.RetiroResponse;
import com.pesoexpress.operations.schema.ReversoRequest;
import com.pesoexpress.operations.schema.ReversoResponse;
import com.pesoexpress.service.OperationService;

@Endpoint
public class OperationsEndpoint {

	private static final String TARGET_NAMESPACE = "http://www.pesoexpress.com/operations/schema";  
	
	@Autowired
	private OperationService operationService;
	
	 @PayloadRoot(localPart = "EnvioRequest", namespace = TARGET_NAMESPACE)  
	 public @ResponsePayload EnvioResponse getEnvio(@RequestPayload EnvioRequest request){
		 EnvioResponse response  = new EnvioResponse();
		 PesoExpressResp peResponse = operationService.envio(request.getPesoExpressReq());
		 response.setPesoExpressResp(peResponse);
		 return response;
	 }
	 
	 @PayloadRoot(localPart = "RetiroRequest", namespace = TARGET_NAMESPACE)  
	 public @ResponsePayload RetiroResponse getEnvio(@RequestPayload RetiroRequest request){
		 RetiroResponse response  = new RetiroResponse();
		 PesoExpressResp peResponse = operationService.retiro(request.getPesoExpressReq());
		 response.setPesoExpressResp(peResponse);
		 return response;
	 }
	 
	 @PayloadRoot(localPart = "ReversoRequest", namespace = TARGET_NAMESPACE)  
	 public @ResponsePayload ReversoResponse getReverso(@RequestPayload ReversoRequest request){
		 ReversoResponse response  = new ReversoResponse();
		 PesoExpressResp peResponse = operationService.reverso(request.getPesoExpressReq());
		 response.setPesoExpressResp(peResponse);
		 return response;
	 }

	/**
	 * @return the operationService
	 */
	public OperationService getOperationService() {
		return operationService;
	}

	/**
	 * @param operationService the operationService to set
	 */
	public void setOperationService(OperationService operationService) {
		this.operationService = operationService;
	}
	
}
